Home:ALL Converter>Exception "waiting for replication timed out" received for MongoDB Bulk Write operation

Exception "waiting for replication timed out" received for MongoDB Bulk Write operation

Ask Time:2019-03-20T12:27:46         Author:leon

Json Formatter

We have two servers for MongoDB servers, one is primary, the other is configured as replica.

We use PHP to bulk write a list of updates to MongoDB. From the server logs, we do some a small amount of exceptions of "waiting for replication timed out" in our server logs.

  1. What could be the reason of the exception? The network between two servers are stable.
  2. When we receive the exception "waiting for replication timed out", we can assume the Bulk Write operation has successfully updated the target documents to the primary server?

The bulk write part of the PHP codes:

 try {
            $manager = new MongoDB\Driver\Manager("mongodb://" . DB_HOST);
            $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 10000);
            $result = $manager->executeBulkWrite($DBName . '.' . $collection, $bulk, $writeConcern);
            return $result;
        } catch (Exception $ee) {
            AppendToLogFile(ERROR_Internal_Error, 'Script:' . __FILE__ . ', LINE:' . __LINE__ . ',$ee:' . $ee->getMessage());
            continue;
        }

Thanks!

Author:leon,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55253600/exception-waiting-for-replication-timed-out-received-for-mongodb-bulk-write-op
yy